import os
import shutil


def move(image_path, xml_path, txt_path):
    sets = ['train', 'val']
    for set in sets:
        image_ids = open(f'{txt_path}/{set}.txt').read().strip().split('\n')
        if not os.path.exists(f'{image_path}/{set}'):
            os.makedirs(f'{image_path}/{set}')
        if not os.path.exists(f'{xml_path}/{set}'):
            os.makedirs(f'{xml_path}/{set}')
        for filename in image_ids:
            shutil.move(f'{image_path}/{filename}.jpg', f'{image_path}/{set}/{filename}.jpg')  # 移动文件 源文件 移动后文件
            shutil.move(f'{xml_path}/{filename}.xml', f'{xml_path}/{set}/{filename}.xml')  # 移动文件 源文件 移动后文件


if __name__ == '__main__':
    image_path = '../images'
    xml_path = '../image_annotation'
    txt_path = '../txt'
    # 通过xml绘制带框框的图片
    move(image_path, xml_path, txt_path)
    # 检查xml名称是否与内部filename相同
